Rails: Novice to Ninja by Glenn Goodrich Patrick Lenz

Rails: Novice to Ninja by Glenn Goodrich Patrick Lenz

Author:Glenn Goodrich, Patrick Lenz [Glenn Goodrich, Patrick Lenz]
Language: eng
Format: epub, mobi
Publisher: SitePoint Pty. Ltd.
Published: 2016-11-25T05:00:00+00:00


Checking out the routes

You've guessed right if you've pointed at all the routes with a declaration of votes#<method> in them. What's interesting to see here is that the URLs look like this: stories/:story_id/votes

What we've created is a so-called nested route. A vote object is nested below the story object and cannot be accessed by simply going to a URL like /votes or /votes/1, but must be accessed with a prefix naming the associated story first, such as stories/1/votes.

Of note is the naming of the URL helpers. Instead of employing the standard votes_path method to refer to the votes index, our nested route has provided us with the story_votes_path method. Similarly, the helper to access a single vote would not be vote_path but story_vote_path. We'd receive an error if we tried to use incorrectly named helpers. In addition, we must specify the parent story of the vote when generating vote URLs. Confused yet? Let's see it in practice!



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.